﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ValidAnagram
{
    public class Solution
    {
        public bool IsAnagram(string s, string t)
        {
            var map = new Dictionary<char, int>();
            foreach (var c in s)
            {
                if (map.ContainsKey(c))
                {
                    map[c]++;
                }
                else
                {
                    map.Add(c, 1);
                }
            }

            foreach (var c in t)
            {
                if (!map.ContainsKey(c))
                {
                    return false;
                }

                map[c]--;
                if (map[c] < 0) 
                {
                    return false;
                }
            }

            return map.Values.Sum() == 0;
        }
    }
}
